package com.renu.jdependencyanalyser.freemarker;

import com.intellij.ide.fileTemplates.impl.UrlUtil;
import com.renu.jdependencyanalyser.core.ClassBorderGene;
import com.renu.jdependencyanalyser.core.ProjectInfo;
import com.renu.jdependencyanalyser.freemarker.data.ClsData;
import freemarker.template.Template;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;

public class ClsUMLProcessor extends AbstractProcessor {
    //private  ProjectInfo projectInfo;

    //private  ClassModel classModel;
    //private ClassBorderGene classBorderGene;

    private ClsData clsData;


    public ClsUMLProcessor(ProjectInfo projectInfo, ClassBorderGene classBorderGene) {
        super();
        this.clsData = new ClsData(projectInfo,classBorderGene);
    }

    @Override
    protected Object getModel() {
        HashMap<String, Object> model = new HashMap<>();
        model.put("clsName",clsData.getClsName());
        model.put("outerFields",clsData.getOuterFlds());
        model.put("indirOuterMthds",clsData.getIndirOuterMthds());
        model.put("dirOuterMthds",clsData.getDirOuterMthds());
        model.put("extendRelations",clsData.getExtendRelations());
        model.put("dependRelations",clsData.getDependRelations());
        model.put("implementRelations",clsData.getImplementRelations());

        return model;

    }



    @Override
    protected Template getTemplate() throws IOException {
        //Configuration configuration = new Configuration(Configuration.VERSION_2_3_28);
        String templateContent = UrlUtil.loadText(ClsUMLProcessor.class.getResource(File.separator + "template" + File.separator + "ClassTemplate.ftl"));
        //StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
        stringTemplateLoader.putTemplate("ClassTemplate",templateContent);

        return configuration.getTemplate("ClassTemplate");
    }

    @Override
    protected Writer getWriter() {
        return new StringWriter();
    }


}
